﻿using System;
using System.ServiceModel;
using Conducido.WcfMessageLogger.Services.Behaviors.LogModel;
using Services.Host.Contracts;
using Services.Host.Interface;

namespace Services.Host
{
    [ServiceBehavior(Namespace = "http://schemas.conducido.nl/BizTalkOpSuite/Messagelog/2012/01")]
    public class LogService : ILogService
    {
        #region ILogService Members

        public void LogMessage(MessageToLog messageToLog)
        {
            using(var context = new MessagelogEntities())
            {
                var log = new Log
                              {
                                  CorrelationId = messageToLog.CorrelationId,
                                  Direction = messageToLog.MessageDirection.ToString(),
                                  Message = messageToLog.Message.ToString(),
                                  MessageId = messageToLog.MessageId,
                                  Operation = messageToLog.Operation,
                                  Process = messageToLog.Process,
                                  ProcessId = messageToLog.ProcessId,
                                  Servername = messageToLog.Servername,
                                  Service = messageToLog.Service,
                                  Timestamp = messageToLog.Timestamp
                              };
                context.Log.AddObject(log);
                context.SaveChanges();
            }
        }

        #endregion
    }
}